package freespiritsocial.io.user.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.model.bean.PlaceAutocompleteBean
import freespiritsocial.io.user.data.model.bean.PlaceAutocompleteBean.Companion.LOCATION_API
import freespiritsocial.io.user.databinding.ItemLocationBinding
import freespiritsocial.io.user.util.KeyWordUtil

/**
 * 地址适配器
 */
class LocationAdapter(
    private val maxSize: Int = -1,
    data: ArrayList<PlaceAutocompleteBean> = arrayListOf(),
    layoutResIdRes: Int = R.layout.item_location
):
    BaseQuickAdapter<PlaceAutocompleteBean,BaseDataBindingHolder<ItemLocationBinding>>(layoutResIdRes,data) {

    override fun getItemCount(): Int {
        return if (maxSize > 0) maxSize else super.getItemCount()
    }

    var keyword = ""

    override fun convert(holder: BaseDataBindingHolder<ItemLocationBinding>,item: PlaceAutocompleteBean) = with(holder.dataBinding) {
        this?.tvLocation?.setCompoundDrawablesWithIntrinsicBounds(
            if (item.type == LOCATION_API) R.mipmap.icon_location_item_type else R.mipmap.icon_place_item_type,
            0,
            0,
            0
        )
        this?.tvLocation?.text = "${item.address} ${item.place}"

//        firstColor="@{}"
//        firstText='@{first}'
//        secondColor="@{0xff6C778B}"
//        secondText='@{sec}'
    }
}